﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;

public partial class Pages_Admin_adaugareAtribute : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
    {

    }
 
    protected void adauga_Click(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection(GetConnectionString());
        SqlCommand command = new SqlCommand();
        command.Parameters.Add("atribut", SqlDbType.Int);
        command.Parameters["atribut"].Value = atribute_val_ddl.SelectedValue;

        command.Parameters.Add("produs", SqlDbType.Int);
        command.Parameters["produs"].Value = produs_ddl.SelectedValue;
            
        command.CommandText = "INSERT into Product_Atributes(AtributID, ProductID) VALUES(@atribut, @produs)";

        command.Connection = connection;
        connection.Open();
        
        command.ExecuteNonQuery();
        
        connection.Close();

        Response.RedirectToRoutePermanent("adaugareAtribute");

    }

    string GetConnectionString(string connection_name = "StoreDBConnectionString")
    {
        string connection = string.Empty;

        connection = ConfigurationManager.ConnectionStrings[connection_name].ConnectionString;

        return connection;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection(GetConnectionString());
        SqlCommand command = new SqlCommand();
        command.Parameters.Add("categorie", SqlDbType.Int);
        command.Parameters["categorie"].Value = atribute_cat2_ddl.SelectedValue;

        command.Parameters.Add("valoare", SqlDbType.VarChar);
        command.Parameters["valoare"].Value = valoare.Text.ToString().Trim();

        command.CommandText = "INSERT into Atribute_Value(AtributeTypeID, atribut_value) VALUES(@categorie, @valoare)";

        command.Connection = connection;
        connection.Open();

        command.ExecuteNonQuery();

        connection.Close();

        Response.RedirectToRoutePermanent("adaugareAtribute");
    }
}